/**
 * Created by yunpeng on 2015/4/9.
 */
var Table = require('../utils/Table').Table;
var Bid = function(starttime,endtime,price,inforid,carrierid,createtime) {

    this.starttime = starttime;
    this.endtime = endtime;
    this.inforid = inforid;
    this.carrierid = carrierid;
    this.price = price;
    this.createtime = createtime;
    Bid.prototype.save = function(data,callback){
        new Table('bid').insert(data,function(err){
            if(err){
                callback(false);
            }else{
                callback(true);
            }
        });
    };
    if(typeof this.getList !='function'){//商家列表
        Bid.prototype.getList = function(params,page,callback){
            var columns = ' l.id,l.endtime,l.inforid,l.carrierid,u.company,u.headerpath,u.care,u.phone,u.attitude,u.corresponds,u.evaluationnum,l.price,date_format(l.starttime,"%Y-%m-%d") as starttime,date_format(l.endtime,"%Y-%m-%d") as endtime';
            //var condition1 =' AND l.userid='+params[0];
            //if(params[1]&&params[1]!='null'){//开始时间
                var condition1=" AND l.inforid=i.id AND l.carrierid=u.id AND l.inforid = "+params;
            //}

            new Table(' bid l,information i ,users u ').queryPage(columns,condition1,page,function(err,result){
                callback(result);
            });
        }
    }

    if(typeof this.companyDetails !='function'){
        Bid.prototype.companyDetails=function(userid,callback){
            new Table().executeSql(" select * FROM users l WHERE l.id=(?) ",[userid],function(err,result){
                if(err){
                    callback(['']);
                }else{
                    callback(result);
                }
            });
        }
    }
    if(typeof this.getBid !='function'){
        Bid.prototype.getBid=function(arrs,callback){
            new Table().executeSql(" select * FROM bid l WHERE l.inforid=(?) AND l.carrierid=(?) ",arrs,function(err,result){
                if(err){
                    callback(['']);
                }else{
                    callback(result);
                }
            });
        }
    }
}
exports.Bid = Bid;